package csab.core;

import java.io.IOException;

import org.newdawn.slick.SavedState;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.Log;

public class PlayerStats 
{
	private static SavedState savedstate;
	private static int health;
	private static String playerName;
	private static int killCount;
	private static int winCount;
	private static int currentLevel;
	private static String gameName;
	private static int experience;
	
	static
	{
		init();
	}
	
	private static void init()
	{
		try 
		{
			savedstate =  new SavedState("tosSaveData");
			savedstate.load();
		} 
		catch (SlickException e) 
		{
			Log.error(e.getMessage());
		} 
		catch (IOException e) 
		{
			Log.error("Error loading playerstats!");
		}
		playerName = savedstate.getString("playerName", "");
		gameName = savedstate.getString("gameName", "");
		winCount = (int)(savedstate.getNumber("winCount", 0));
		killCount = (int)(savedstate.getNumber("killCount",0));
		currentLevel = (int)(savedstate.getNumber("currentLevel", 1));
		experience = (int)(savedstate.getNumber("experience", 0));
		health = (int)(savedstate.getNumber("health", 200));
	}
	
	public static void clearData() throws IOException
	{
		savedstate.clear();
		savedstate.save();
		init();
	}
	
	public static int getHealth()
	{
		return health;
	}
	public static int getKillCount()
	{
		return killCount;
	}
	public static int getWinCount()
	{
		return winCount;
	}
	public static int getCurrentLevel()
	{
		return currentLevel;
	}
	public static int getExperience()
	{
		return experience;
	}
	public static String getPlayerName()
	{
		return playerName;
	}
	public static String getGameName()
	{
		return gameName;
	}
	
	public static void setHealth(int h)
	{
		health = h;
	}
	public static void setKillCount(int k)
	{
		killCount = k;
	}
	public static void setWinCount(int w)
	{
		winCount = w;
	}
	public static void setCurrentLevel(int c)
	{
		currentLevel = c;
	}
	public static void setExperience(int e)
	{
		experience = e;
	}
	public static void setPlayerName(String n)
	{
		playerName = n;
	}
	public static void setGameName(String g)
	{
		gameName = g;
	}
	
	public static void save() throws IOException
	{
		savedstate.setNumber("health", health);
		savedstate.setNumber("experience", experience);
		savedstate.setNumber("currentLevel", currentLevel);
		savedstate.setNumber("winCount", winCount);
		savedstate.setNumber("killCount", killCount);
		savedstate.setString("playerName", playerName);
		savedstate.setString("gameName", gameName);
		savedstate.save();
	}
}


